package com.youxuan.controller;

import com.youxuan.pojo.entity.Goods;
import com.youxuan.pojo.entity.ResponseResult;
import com.youxuan.pojo.vo.GoodsListVo;
import com.youxuan.pojo.vo.PageVo;
import com.youxuan.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/goods")
@Api(tags = "商品")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @ApiOperation("商品列表")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "categoryId",value = "分类id，不传则随机返回")
    )
    @GetMapping("/list")
    public ResponseResult<PageVo<Goods>> getList(Integer pageNum, Integer pageSize, Integer categoryId){
        return goodsService.getList(pageNum,pageSize,categoryId);
    }

    @ApiOperation("查找商品")
    @GetMapping("/findGoods")
    public ResponseResult<List<Goods>> findGoods(String antistop){
        return goodsService.findGoods(antistop);
    }

    @ApiOperation("商品详情")
    @GetMapping("/getSingle")
    public ResponseResult<Goods> getSingle(Long goodsId){
        return ResponseResult.okResult(goodsService.getGoods(goodsId));
    }

    @ApiOperation("添加商品")
    @PostMapping("/addSingle")
    public ResponseResult addSingle(Goods goods){
        return goodsService.addSingle(goods);
    }

    @ApiOperation("删除商品")
    @PostMapping("/removeSingle")
    public ResponseResult removeSingle(@RequestBody Goods goods){
        return goodsService.removeSingle(goods.getId().intValue());
    }

    @ApiOperation("修改商品")
    @PostMapping("/updateSingle")
    public ResponseResult updateSingle(@RequestBody Goods goods){
        return goodsService.updateSingle(goods);
    }

}
